﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using DAL;

namespace BLL
{
   public class ClsKetQuaBomTNBus
    {
       public ClsKetQuaBomTNInfo Info = new ClsKetQuaBomTNInfo();
        public DataTable TimKiemGK()
        {
            ClsDataAccess oConnection = new ClsDataAccess();
            string strSql = @"SELECT TTCHUNG.TenGK,BomThiNghiem.MaBomTN,BomThiNghiem.ThoiGianBD,BomThiNghiem.ThoiGianKT,BomThiNghiem.HeSoTham,BomThiNghiem.HSDanNuoc,BomThiNghiem.HSNhaNuoc,BomThiNghiem.HSTruyenAp,BomThiNghiem.BKAnhHuong,KieuBomTN.TenKieuBomTN
                              FROM TTCHUNG,KieuBomTN,BomThiNghiem
                              WHERE TTCHUNG.MaGK= BomThiNghiem.MaGK 
                              AND BomThiNghiem.MaKieuBomTN=KieuBomTN.MaKieuBomTN
                              AND TTCHUNG.MaGK like'%" + Info.MaGK + 
                              "%'AND TTCHUNG.Tinh like'%"+Info.MaTinh +"%'";

            if (oConnection.ExecuteSelect(strSql))
            {
                oConnection.ODataTable.Columns.Add("STT");
                int i = 0;
                foreach (DataRow oDRow in oConnection.ODataTable.Rows)
                {
                    oDRow["STT"] = (i + 1);
                    i++;
                }
                return oConnection.ODataTable;
            }
            else
            {
                return null;
            }
        }

        public DataTable SelectAll()
        {
             ClsDataAccess oConnection = new ClsDataAccess();
             string strSql = @"SELECT TTCHUNG.TenGK,BomThiNghiem.MaBomTN,BomThiNghiem.ThoiGianBD,BomThiNghiem.ThoiGianKT,BomThiNghiem.HeSoTham,BomThiNghiem.HSDanNuoc,BomThiNghiem.HSNhaNuoc,BomThiNghiem.HSTruyenAp,BomThiNghiem.BKAnhHuong,KieuBomTN.TenKieuBomTN
                              FROM TTCHUNG,KieuBomTN,BomThiNghiem
                              WHERE TTCHUNG.MaGK= BomThiNghiem.MaGK 
                              AND BomThiNghiem.MaKieuBomTN=KieuBomTN.MaKieuBomTN
                              AND TTCHUNG.Tinh like'%" + Info.MaTinh +"%'";
            //string strSql = @"SELECT * From ThachHoc";
            if (oConnection.ExecuteSelect(strSql))
            {
                oConnection.ODataTable.Columns.Add("STT");
                int i = 0;
                foreach (DataRow oDRow in oConnection.ODataTable.Rows)
                {
                    oDRow["STT"] = (i + 1);
                    i++;
                }
                return oConnection.ODataTable;
            }
            else return null;
        }
        public bool Them()
        {
            string strSql = "EXECUTE InsertBomThiNghiem'" + Info.MaGK + "','" + Info.MaBomTN + "','" + Info.MaKieuBomTN + "','" + Info.ThoiGianBD + "','" + Info.ThoiGianKT + "','" + Info.HeSoTham + "','" + Info.HSDanNuoc + "','" + Info.HSNhaNuoc + "','" + Info.HSTruyenAp + "','" + Info.BKAnhHuong + "'";

            ClsDataAccess oConnection = new ClsDataAccess();
            return (oConnection.ExecuteStoredProcedure(strSql));
        }

        public bool Sua()
        {
            string strSql = "EXECUTE UpdateBomThiNghiem'" + Info.MaGK + "','" + Info.MaBomTN + "','" + Info.MaKieuBomTN + "','" + Info.ThoiGianBD + "','" + Info.ThoiGianKT + "','" + Info.HeSoTham + "','" + Info.HSDanNuoc + "','" + Info.HSNhaNuoc + "','" + Info.HSTruyenAp + "','" + Info.BKAnhHuong + "'";
            ClsDataAccess oConnection = new ClsDataAccess();
            return (oConnection.ExecuteStoredProcedure(strSql));
        }
        public bool xoa()
        {
            string strSql = "EXECUTE DeleteBomThiNghiem'" + Info.MaBomTN + "'";
            ClsDataAccess oConnection = new ClsDataAccess();
            return (oConnection.ExecuteStoredProcedure(strSql));
        }
    }
}
